{extend name='public/base' /}
{block name='content'}
{include file='public/content_header' /}
<section class="content">
    <div class="row">
        <div class="col-md-12">
            <div class="card">
                <!-- 表单头部 -->
                <div class="card-header">
                    <div class="btn-group">
                        <a class="btn flat btn-sm btn-default BackButton">
                            <i class="fas fa-arrow-left"></i>
                            返回
                        </a>
                    </div>
                </div>
                <!-- 表单 -->
                <form id="dataForm" class="form-horizontal dataForm" action="" method="post" enctype="multipart/form-data">
                    <!-- 表单字段区域 -->
                    <div class="card-body">
                        <div class="form-group row rowSelect">
    <label for="shop_id" class="col-sm-2 col-form-label">商铺</label>
    <div class="col-sm-10 col-md-4 formInputDiv">
        <select name="shop_id" id="shop_id" class="form-control select2bs4 fieldSelect" data-placeholder="请选择商铺">
            <option value=""></option>
            {foreach name='shop_list' id='item'}
    <option value="{$item.id}" {if isset($data) && $data.shop_id==$item.id}selected{/if}>
        {$item.name}
    </option>
{/foreach}
        </select>
    </div>

    <script>
        $('#shop_id').select2({
            theme: 'bootstrap4'
        });
    </script>
</div>
<div class="form-group row rowSelect">
    <label for="shop_cate_id" class="col-sm-2 col-form-label">商品分类</label>
    <div class="col-sm-10 col-md-4 formInputDiv">
        <select name="shop_cate_id" id="shop_cate_id" class="form-control select2bs4 fieldSelect" data-placeholder="请选择商品分类">
            <option value=""></option>
            {foreach name='shop_cate_list' id='item'}
    <option value="{$item.id}" {if isset($data) && $data.shop_cate_id==$item.id}selected{/if}>
        {$item.name}
    </option>
{/foreach}
        </select>
    </div>

    <script>
        $('#shop_cate_id').select2({
            theme: 'bootstrap4'
        });
    </script>
</div>
<div class="form-group row rowText">
    <label for="title" class="col-sm-2 col-form-label">标题</label>
    <div class="col-sm-10 col-md-4 formInputDiv">
        <input id="title" name="title" value="{$data.title|default=''}" placeholder="请输入标题" type="text" class="form-control fieldText">
    </div>
</div>
<div class="form-group row rowText">
    <label for="desc" class="col-sm-2 col-form-label">描述</label>
    <div class="col-sm-10 col-md-4 formInputDiv">
        <input id="desc" name="desc" value="{$data.desc|default=''}" placeholder="请输入描述" type="text" class="form-control fieldText">
    </div>
</div>
    <div class="form-group row rowImage">
        <label for="cover" class="col-sm-2 col-form-label">封面</label>
        <div class="col-sm-10 col-md-4 formInputDiv"> 
            <div class="input-group">
                <input id="cover_file" name="cover_file" type="file" class="file-loading " data-initial-preview="{if isset($data)}{$data.cover}{/if}">
                <input name="cover" id="cover" value="{$data.cover|default=''}" hidden placeholder="请上传图片" class="fieldImage">
                <script>
                     initUploadImg('cover');
                </script>            
            </div>
        </div>
    </div>
<div class="form-group row rowMultiImage">
    <label for="images" class="col-sm-2 col-form-label">图片</label>
    <div class="col-sm-10 col-md-8 formInputDiv">
        <div class="input-group">
            <input id="images_file" name="images_file" type="file" class="file-loading " multiple>
            <input name="images" id="images" value="{$data.images|default=''}" hidden placeholder="请上传图片" class="fieldMultiImage">
            <script>
                initUploadMultiImg('images');
            </script>            
        </div>
    </div>
</div><div class="form-group row rowNumber">
    <label for="price" class="col-sm-2 col-form-label">现价</label>
    <div class="col-sm-10 col-md-4 formInputDiv">
         <div class="input-group">
            <input id="price" name="price" value="{$data.price|default='0.00'}" placeholder="请输入现价" type="number" class="form-control fieldNumber">
        </div>
    </div>

    <script>
        $('#price')
            .bootstrapNumber({
                upClass: 'success',
                downClass: 'primary',
                center: true
            });
    </script>
</div>
<div class="form-group row rowNumber">
    <label for="original_price" class="col-sm-2 col-form-label">原价</label>
    <div class="col-sm-10 col-md-4 formInputDiv">
         <div class="input-group">
            <input id="original_price" name="original_price" value="{$data.original_price|default='0.00'}" placeholder="请输入原价" type="number" class="form-control fieldNumber">
        </div>
    </div>

    <script>
        $('#original_price')
            .bootstrapNumber({
                upClass: 'success',
                downClass: 'primary',
                center: true
            });
    </script>
</div>
<div class="form-group row rowNumber">
    <label for="sale" class="col-sm-2 col-form-label">销量</label>
    <div class="col-sm-10 col-md-4 formInputDiv">
         <div class="input-group">
            <input id="sale" name="sale" value="{$data.sale|default='0'}" placeholder="请输入销量" type="number" class="form-control fieldNumber">
        </div>
    </div>

    <script>
        $('#sale')
            .bootstrapNumber({
                upClass: 'success',
                downClass: 'primary',
                center: true
            });
    </script>
</div>
<div class="form-group row rowNumber">
    <label for="inventory" class="col-sm-2 col-form-label">库存</label>
    <div class="col-sm-10 col-md-4 formInputDiv">
         <div class="input-group">
            <input id="inventory" name="inventory" value="{$data.inventory|default='0'}" placeholder="请输入库存" type="number" class="form-control fieldNumber">
        </div>
    </div>

    <script>
        $('#inventory')
            .bootstrapNumber({
                upClass: 'success',
                downClass: 'primary',
                center: true
            });
    </script>
</div>
<div class="form-group row rowEditor">
    <label for="argument" class="col-sm-2 col-form-label">商品参数</label>
        <div class="col-sm-10">
            <div id="argumentEditor">{$data.argument|raw|default='<p></p>'}</div>
            <textarea id="argument" name="argument" style="display: none">{$data.argument|raw|default=''}</textarea>
        </div>
    <script>
        var E = E||window.wangEditor;
        if(editor_argument!==undefined){
            editor_argument.destroy();
        }
        var editor_argument = new E('#argumentEditor');
        editor_argument.config.zIndex=1000;
        editor_argument.config.uploadImgServer = editorUploadUrl;
        editor_argument.config.uploadFileName = 'file';
        editor_argument.create();
        editor_argument.config.onchange = function (newHtml) {
            $('#argument').val(newHtml);
        };
</script>
</div>
<div class="form-group row rowEditor">
    <label for="content" class="col-sm-2 col-form-label">商品内容</label>
        <div class="col-sm-10">
            <div id="contentEditor">{$data.content|raw|default='<p></p>'}</div>
            <textarea id="content" name="content" style="display: none">{$data.content|raw|default=''}</textarea>
        </div>
    <script>
        var E = E||window.wangEditor;
        if(editor_content!==undefined){
            editor_content.destroy();
        }
        var editor_content = new E('#contentEditor');
        editor_content.config.zIndex=1000;
        editor_content.config.uploadImgServer = editorUploadUrl;
        editor_content.config.uploadFileName = 'file';
        editor_content.create();
        editor_content.config.onchange = function (newHtml) {
            $('#content').val(newHtml);
        };
</script>
</div>
<div class="form-group row rowSwitch">
    <label for="status" class="col-sm-2 col-form-label">状态</label>
    <div class="col-sm-10 col-md-4 formInputDiv">
    <input {if((!isset($data)&&0==1)||(isset($data)&&$data.status==1))}checked{/if}
     class="input-switch"  id="status" value="1" type="checkbox" />
    <input class="switch fieldSwitch" placeholder="状态" name="status" value="{$data.status|default='0'}" hidden />
    </div>

    <script>
        $('#status').bootstrapSwitch({
            onText: "是",
            offText: "否",
            onColor: "success",
            offColor: "danger",
            onSwitchChange: function (event, state) {
                $(event.target).closest('.bootstrap-switch').next().val(state ? '1' : '0').change();
            }
        });
    </script>
</div>
<div class="form-group row rowSwitch">
    <label for="top" class="col-sm-2 col-form-label">是否置顶</label>
    <div class="col-sm-10 col-md-4 formInputDiv">
    <input {if((!isset($data)&&0==1)||(isset($data)&&$data.top==1))}checked{/if}
     class="input-switch"  id="top" value="1" type="checkbox" />
    <input class="switch fieldSwitch" placeholder="是否置顶" name="top" value="{$data.top|default='0'}" hidden />
    </div>

    <script>
        $('#top').bootstrapSwitch({
            onText: "是",
            offText: "否",
            onColor: "success",
            offColor: "danger",
            onSwitchChange: function (event, state) {
                $(event.target).closest('.bootstrap-switch').next().val(state ? '1' : '0').change();
            }
        });
    </script>
</div>
<div class="form-group row rowNumber">
    <label for="sort" class="col-sm-2 col-form-label">排序</label>
    <div class="col-sm-10 col-md-4 formInputDiv">
         <div class="input-group">
            <input id="sort" name="sort" value="{$data.sort|default='0'}" placeholder="请输入排序" type="number" class="form-control fieldNumber">
        </div>
    </div>

    <script>
        $('#sort')
            .bootstrapNumber({
                upClass: 'success',
                downClass: 'primary',
                center: true
            });
    </script>
</div>

                    </div>
                    <!-- 表单底部 -->
                    <div class="card-footer">
                        <div class="row">
                            <div class="col-sm-2">
                            </div>

                            <div class="col-sm-10 col-md-4 formInputDiv">

                                <div class="btn-group">
                                    <button type="submit" class="btn btn-sm btn-primary dataFormSubmit">
                                        保 存
                                    </button>
                                </div>
                                <div class="btn-group">
                                    <button type="reset" class="btn btn-sm btn-default dataFormReset">
                                        重 置
                                    </button>
                                </div>

                                {if !isset($data)}
                                <div class="btn-group float-right createContinueDiv">
                                    <input type="checkbox" class="form-check-input" value="1" id="_create" name="_create" title="继续添加数据">
                                    <label class="form-check-label" for="_create">继续添加</label>
                                </div>
                                {/if}
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</section>
<script>
    /** 表单验证 **/
    $('#dataForm').validate({
        rules: {
                'shop_id': {
                required: true,

    },
    'shop_cate_id': {
                required: true,

    },
    'title': {
                required: true,

    },
    'desc': {
                required: true,

    },
    'cover': {
                required: true,

    },
    'images[]': {
                required: true,

    },
    'price': {
                required: true,

    },
    'original_price': {
                required: true,

    },
    'sale': {
                required: true,
        number: true,

    },
    'inventory': {
                required: true,
        number: true,

    },
    'argument': {
                required: true,

    },
    'content': {
                required: true,

    },
    'status': {
                required: true,

    },
    'top': {
                required: true,

    },
    'sort': {
                required: true,
        number: true,

    },

        },
        messages: {
                'shop_id': {
               required: "商铺不能为空",

    },
    'shop_cate_id': {
               required: "商品分类不能为空",

    },
    'title': {
               required: "标题不能为空",

    },
    'desc': {
               required: "描述不能为空",

    },
    'cover': {
               required: "封面不能为空",

    },
    'images[]': {
               required: "图片不能为空",

    },
    'price': {
               required: "现价不能为空",

    },
    'original_price': {
               required: "原价不能为空",

    },
    'sale': {
               required: "销量不能为空",
        number: "销量必须为纯数字",

    },
    'inventory': {
               required: "库存不能为空",
        number: "库存必须为纯数字",

    },
    'argument': {
               required: "商品参数不能为空",

    },
    'content': {
               required: "商品内容不能为空",

    },
    'status': {
               required: "状态不能为空",

    },
    'top': {
               required: "是否置顶不能为空",

    },
    'sort': {
               required: "排序不能为空",
        number: "排序必须为纯数字",

    },

        }
    });
</script>
{/block}